// pages/projectList/projectList.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: 1,
    storeId: null,
    leftList: [],
    rightList: []
  },
  goDetail(e) {
    let index = e.currentTarget.dataset.index
    let id = this.data.rightList[index].id
    let storeId = this.data.rightList[index].storeId
    let status = this.data.rightList[index].isVip
    if (status === 'Y' && getApp().globalData.isVip !== 'Y' && !getApp().globalData.isLookVip) {
      wx.showToast({
        title: '这是会员专享商品！',
        icon: 'none'
      })
    } else {
      wx.navigateTo({
        url: '/pages/productDetail/productDetail?id=' + id + '&storeId=' + storeId,
      })
    }
  },
  getList () {
    getApp().https.ajax({
      method: 'get',
      url: '/product/listNew',
      data: {
        storeId: this.data.storeId,
        classifyId: this.data.id
      }
    }).then(({ data }) => {
      this.setData({
        rightList: data.rows
      })
    })
  },
  switchLeft (e) {
    let id = e.currentTarget.dataset.id
    this.setData({
      id
    }, () => {
      this.getList()
    })
  },
  getClassList () {
    getApp().https.ajax({
      method: 'get',
      url: '/storeClassify/second'
    }).then(({ data }) => {
      this.setData({
        leftList: data
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad({id = 0, storeId = 0}) {
    if (id !== 0 && storeId !== 0) {
      this.setData({
        id: parseInt(id),
        storeId: parseInt(storeId)
      })
    }
    this.getClassList()
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})